Skip to content

gh-154936: Fix JSON control character error position - #154941

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
yangbaechu:gh-154936-json-control-character-position
Jul 31, 2026
Merged

gh-154936: Fix JSON control character error position#154941
serhiy-storchaka merged 1 commit into
python:mainfrom
yangbaechu:gh-154936-json-control-character-position

Conversation

@yangbaechu

@yangbaechu yangbaechu commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Closes #154936.

Report the actual position of invalid literal control characters in the pure Python JSON decoder. Previously, the scanner passed Match.end(), which points one character past the consumed control character, causing JSONDecodeError.pos, lineno, and colno to identify the following character instead.

Use end - 1 only in the strict invalid-control-character branch and extend the existing ASCII control-character test to verify all three location attributes for U+0000 through U+001F. The shared JSON tests cover both the pure Python and C decoders.

Tests

  • ./python -m test test_json
  • make patchcheck

Report the index of the invalid literal control character instead of
the following index in the pure Python decoder.
@python-cla-bot

python-cla-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 31, 2026
@serhiy-storchaka
serhiy-storchaka merged commit adf836e into python:main Jul 31, 2026
65 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @yangbaechu for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 31, 2026

Copy link
Copy Markdown

GH-154974 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 31, 2026
@bedevere-app

bedevere-app Bot commented Jul 31, 2026

Copy link
Copy Markdown

GH-154975 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 31, 2026
@bedevere-app

bedevere-app Bot commented Jul 31, 2026

Copy link
Copy Markdown

GH-154976 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 31, 2026
hugovk pushed a commit that referenced this pull request Jul 31, 2026
… (#154974)

Co-authored-by: yangbaechu <45089264+yangbaechu@users.noreply.github.com>
hugovk pushed a commit that referenced this pull request Jul 31, 2026
… (#154975)

Co-authored-by: yangbaechu <45089264+yangbaechu@users.noreply.github.com>
hugovk pushed a commit that referenced this pull request Jul 31, 2026
… (#154976)

Co-authored-by: yangbaechu <45089264+yangbaechu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pure Python JSON decoder reports the error position one character past an invalid control character

2 participants